package com.CGFrame.struts.bean.category;

import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import com.CGFrame.struts.POJOs.Category;
import com.CGFrame.struts.POJOs.Company;
import com.CGFrame.struts.bean.ProjectOperate;
import com.CGFrame.struts.bean.ProjectOperateFactory;

public class CategoryBean {

	public List getCategorys(){
		 ProjectOperate pop= ProjectOperateFactory.getprojectOperate();
		 List list=pop.Query("Category", null, null, null);
		 return list;
	}
	
	public Category getCateById(String id){
		ProjectOperate pop= ProjectOperateFactory.getprojectOperate();
		Category category=(Category)pop.UniqueQuery("Category", "categoryId,"+id);
		return category;
	}
	
	public Integer createCategory(String companyId,String cateName,String cateEname,String cateType){
		ProjectOperate pop = ProjectOperateFactory.getprojectOperate();
		Category cate=new Category();
		cate.setCategoryEnglishName(cateEname);
		cate.setCategoryName(cateName);
		cate.setCategoryType(cateType);
		Company c = (Company)pop.UniqueQuery("Company", "companyId,"+companyId);
		cate.setCompany(c);
		pop.saveObject(cate);
		return cate.getCategoryId();
	}
	
	public void delCategory(Integer id){
		ProjectOperate pop= ProjectOperateFactory.getprojectOperate();
		pop.deleteObject( "Category", id );
	}
	
	public Set getShotCategoryNames(){
		HashSet<String> hs=new HashSet<String>();
		ProjectOperate pop= ProjectOperateFactory.getprojectOperate();
		List list=pop.Query("Category", null, null, null);
		for(Iterator iter=list.iterator();iter.hasNext();){
			Category c=(Category)iter.next();
			if(c.getCategoryType().equals("Shot")){
				hs.add(c.getCategoryName());
			}
		}
		return hs;
	}
	
}
